unit FmGifImg;

interface

uses
  WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Menus,
  MPGifImg;

type
  TForm1 = class(TForm)
    OpenDialog: TOpenDialog;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Open1: TMenuItem;
    Animation1: TMenuItem;
    AnimatingItem: TMenuItem;
    OnceItem: TMenuItem;
    SaveDialog: TSaveDialog;
    Saveas1: TMenuItem;
    Exit1: TMenuItem;
    N2: TMenuItem;
    Image: TImage;
    N1: TMenuItem;
    Speed1: TMenuItem;
    procedure Open1Click(Sender: TObject);
    procedure AnimatingItemClick(Sender: TObject);
    procedure OnceItemClick(Sender: TObject);
    procedure Animation1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Saveas1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Speed1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Open1Click(Sender: TObject);
begin
  if OpenDialog.Execute then
    Image.Picture.LoadFromFile(OpenDialog.FileName);
end;

procedure TForm1.AnimatingItemClick(Sender: TObject);
begin
  if (Image.Picture.Graphic <> nil) and (Image.Picture.Graphic is TGIFImage) then
    with TGIFImage(Image.Picture.Graphic) do
      Animating:= not Animating;
end;

procedure TForm1.OnceItemClick(Sender: TObject);
begin
  if (Image.Picture.Graphic <> nil) and (Image.Picture.Graphic is TGIFImage) then
    TGIFImage(Image.Picture.Graphic).AnimateOnce;
end;

procedure TForm1.Animation1Click(Sender: TObject);
begin
  if (Image.Picture.Graphic <> nil) and (Image.Picture.Graphic is TGIFImage) then
    with TGIFImage(Image.Picture.Graphic) do
    begin
      AnimatingItem.Enabled:= true;
      AnimatingItem.Checked:= Animating;
      OnceItem.Enabled:= not Animating;
      Speed1.Enabled:= true;
    end
  else
  begin
    AnimatingItem.Enabled:= false;
    OnceItem.Enabled:= false;
    Speed1.Enabled:= false;
  end;
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Saveas1Click(Sender: TObject);
begin
  if SaveDialog.Execute then
    Image.Picture.SaveToFile(SaveDialog.FileName);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  OpenDialog.Filter:= GraphicFilter(TGraphic);
end;

procedure TForm1.Speed1Click(Sender: TObject);
begin
  if (Image.Picture.Graphic <> nil) and (Image.Picture.Graphic is TGIFImage) then
    TGIFImage(Image.Picture.Graphic).Interval:= 10;
end;

end.
